template.defaults.imports.TimestampToTime = function (timestamp) {
    var date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = date.getDate() + ' ';
    var h = date.getHours() + ':';
    var m = date.getMinutes() + ':';
    var s = date.getSeconds();
    return Y + M + D + h + m + s;
};


var loading = false; //状态标记
var hasNextPage = false;
var pageNo = 1;
var orderState = -1; //1全部 2待审核 3待售卖
queryList(pageNo);

//下拉刷新
$("#aroundBox").pullToRefresh().on("pull-to-refresh", function () {
    $("#contentTo").html("");
    pageNo = 1;
    queryList(pageNo, function () {
        $("#aroundBox").pullToRefreshDone(); // 重置下拉刷新
    });
});

//上拉加载更多
$('#aroundBox').infinite().on("infinite", function () {
    if (hasNextPage) {
        pageNo++;
        queryList(pageNo, function () {}, true);
    }
});

function queryList(pageNo, callback, isMore) {
    if (loading) return;
    loading = true;
    var params = {};
    params.start = (pageNo - 1) * 20;
    params.limit = 20;
    /* global getCookie */
    params.token = getCookie('token');
    $.get('/antique/api/balanceLog/query_list', params, function (result) {
        if (result.code == 0) {
            if (!isMore) {
                /* global template */
                document.getElementById('contentTo').innerHTML = template('content', result.data);
            } else {
                $("#contentTo").append(template('content', result.data));
            }
            hasNextPage = result.data.hasNextPage;
            if (!result.data.hasNextPage) {
                $('#loadmore').hide();
                $('#nomore').show();
            } else {
                $('#loadmore').show();
                $('#nomore').hide();
            }
            if (callback) callback();
            loading = false;
        }
    });
}